package com.mutual.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import com.mutual.commom.util.ReadXML;
import com.mutual.interceptor.LoginInterceptor;

@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

	@Override
	protected void addInterceptors(InterceptorRegistry registry) {
		// addPathPatterns 用于添加拦截规则
		// excludePathPatterns 用户排除拦截
		registry.addInterceptor(new LoginInterceptor()).
		addPathPatterns("/**").
		excludePathPatterns("/","/user/login","/layui/**","/plugins/**");
		super.addInterceptors(registry);
	}

	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/").setViewName("/login/login");//访问 http://localhost:8001/ 设置login.html 为首次界面
//		registry.addViewController("/index.html").setViewName("login");// 以login为主页
	}
	
	@Override
	protected void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
		String dbFilePath = ReadXML.readProperties("filePath.properties", "dbFilePath");
		String realFilePath = ReadXML.readProperties("filePath.properties", "realFilePath");
		registry.addResourceHandler(dbFilePath+"/**").addResourceLocations("file:"+realFilePath+"/");  
		super.addResourceHandlers(registry);
	}
}
